docs: clarify Astro.url and Astro.params runtime behavior#13903
docs: clarify Astro.url and Astro.params runtime behavior#13903Prayaksh wants to merge 3 commits into
Conversation
✅ Deploy Preview for astro-docs-2 ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Hello! Thank you for opening your first PR to Astro’s Docs! 🎉 Here’s what will happen next:
|
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
There was a problem hiding this comment.
Thanks for your contribution!
If this is indeed a documentation issue (I wouldn't say "probably" means "confirmation"), this addition can be helpful but it doesn't fully fix the issue.
The issue mentions a misleading description in https://docs.astro.build/en/reference/api-reference/#url and potentially in https://docs.astro.build/en/reference/api-reference/#params
@ematipico can you confirm we should fix the docs? Or the fix mentioned by the bot could work and no docs change is required?
Edit: I hadn't followed the linked PR, it seems this might have been fixed in withastro/astro#16808 ?
|
I realize now that I acted on the “probably” comment before the issue was fully confirmed. Thank you for clarifying. I’m still learning the process and will make sure to verify before updating the docs in the future. |
|
The documentation update is still valid, because not all characters can be safely decoded e.g. |
|
Okay, thanks Ema! And no problem @Prayaksh! Are you still willing to check if other pages require an update? It seems we at least need to update https://docs.astro.build/en/reference/api-reference/#url |
|
Thanks @ArmandPhilippot ! I’ve updated the Astro.url and Astro.params API reference docs to clarify the normalization/decoding behavior as well. |
ArmandPhilippot
left a comment
There was a problem hiding this comment.
Thanks for the update! But, I think the upgrade guide addition is misplaced and your description for Astro.params doesn't seem correct.
|
|
||
| `Astro.params` values are automatically decoded, and percent-encoded characters in pathnames or parameters (like `%25`) may appear decoded in `Astro.url` or `Astro.params`. | ||
|
|
||
| If you need the raw request URL with no decoding, use `Astro.request.url` and parse it manually. |
There was a problem hiding this comment.
This doesn't seem to be the right place:
- In "What should I do?" we explain what the user should do based on the change describe above. Here we are explaining that something else has changed without explaining what the user should do.
- This is in the "Removed: Percent-Encoding in routes" section... but here we are not explaining something that has been removed but changed. Even, if this is tied to the same PR, it seems doesn't feel right.
I think we need a new section in "Breaking changes" instead. Probably something similar to this one https://docs.astro.build/en/guides/upgrade-to/v5/#changed-params-no-longer-decoded in the v5 upgrade guide.
|
tried to change as suggested. thanks! |
| A normalized [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) object derived from the current `request.url` value. It is useful for interacting with individual properties of the request URL, like pathname and origin. | ||
|
|
||
| `Astro.url` is equivalent to doing `new URL(Astro.request.url)`. | ||
| Since Astro v6, the pathname is partially decoded during route normalization. This means `Astro.url.pathname` may differ from `new URL(Astro.request.url).pathname` for percent-encoded route segments. |
There was a problem hiding this comment.
| Since Astro v6, the pathname is partially decoded during route normalization. This means `Astro.url.pathname` may differ from `new URL(Astro.request.url).pathname` for percent-encoded route segments. | |
| Since Astro v6, the pathname may be partially decoded during route normalization. This means `Astro.url.pathname` may differ from `new URL(Astro.request.url).pathname` for percent-encoded route segments. |
It's not always the case, so maybe using "may" sounds better
| ## Changed: Route pathname normalization | ||
|
|
||
| Since Astro v6, route pathnames are partially decoded during route normalization. This means `Astro.url.pathname` may differ from `new URL(Astro.request.url).pathname` for percent-encoded route segments. | ||
|
|
||
| This also affects route params derived from normalized pathnames. | ||
|
|
||
| ### What should I do? | ||
|
|
||
| If you need access to the original encoded pathname, use `new URL(Astro.request.url).pathname` instead of `Astro.url.pathname`. | ||
|
|
There was a problem hiding this comment.
This should be an h3 (instead of h2) and h4 (instead of h3) and moved to the Breaking changes section.
| When deploying behind reverse proxies or serverless platforms (for example Vercel), configure `allowedDomains` so Astro can safely trust forwarded host headers during origin validation. | ||
|
|
There was a problem hiding this comment.
As stated at the beginning of this file, it is read-only and auto-generated from the main repo. So, any change should be made in the withastro/astro repo instead.
But, anyway, this sounds unrelated to this PR or the issue.
440fed4 to
16481ea
Compare
|
Sorry for the confusion — my previous commit accidentally included an unrelated change. I've corrected the commit and updated the branch so the PR now only contains the intended documentation changes. I also wasn't able to identify the source PR for this behavior change. If there's a specific PR number that should be referenced, please let me know. |

Description (required)
This PR clarifies the runtime behavior of URL decoding in Astro v6 dynamic routes.
The original issue was reported in the
withastro/astrorepository, and after maintainer confirmation it was identified as a documentation gap rather than a runtime bug.In Astro v6,
Astro.urlreturns a normalized and partially decoded URL, which may differ fromnew URL(Astro.request.url). Additionally,Astro.paramsvalues are automatically decoded. This behavior was not clearly documented in the v6 upgrade guide section covering percent-encoded routes.This update adds a runtime clarification under the “Percent-Encoding in routes” section to reflect the actual behavior and avoid confusion for users working with encoded dynamic route segments.
Related issues & labels (optional)
documentation